package exia.java.core.services;


import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RemoteServiceFactoryClient {

	protected RemoteServiceFactory remoteServiceFactory;
	private final String remoteServiceServerUrl;
	
	
	public RemoteServiceFactoryClient(){
		super();
		this.remoteServiceServerUrl = "rmi://Sebastien-PC:1099/RemoteServiceFactoryServer_ExiaBookshop";
		try {
			if(System.getSecurityManager() == null){
				System.setSecurityManager(new SecurityManager());
			}
			if(remoteServiceServerUrl != null && remoteServiceServerUrl.length() > 0){
				Registry registry = LocateRegistry.getRegistry();
				IRemoteServiceFactory  remoteServiceFactory = (IRemoteServiceFactory )registry.lookup(this.remoteServiceServerUrl);
				if(remoteServiceFactory != null){
					this.remoteServiceFactory = remoteServiceFactory.getServiceFactory();
				}
				System.out.println("AbastractRemoteServiceFactoryClient is connected to:"+this.remoteServiceServerUrl);
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			e.printStackTrace();
		}
	}

}
